package com.packet.utils;

import java.util.ArrayList;
import java.util.List;

// 具体主题类（作业模型）
public class AssignmentModel implements Subject {
    private List<Observer> observers = new ArrayList<>();
    private String assignmentName;
    private String status;

    public void setAssignment(String assignmentName) {
        this.assignmentName = assignmentName;
        notifyObservers(assignmentName,status);
    }

    public void setStatus(String status) {
        this.status = status;
        notifyObservers(assignmentName,status);
    }

    @Override
    public void registerObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObservers(String assignmentName, String status) {
        for (Observer observer : observers) {
            observer.update(assignmentName, status);
        }
    }
}
